import { IsString, IsArray, IsNumber, IsOptional, IsBoolean } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';

export class CreateRecipeDto {
  @ApiProperty({ description: '菜品名称' })
  @IsString()
  name: string;

  @ApiProperty({ description: '食材列表' })
  @IsArray()
  ingredients: string[];

  @ApiProperty({ description: '烹饪步骤' })
  @IsArray()
  steps: string[];

  @ApiProperty({ description: '菜品类型', enum: ['meat', 'vegetable', 'soup'] })
  @IsString()
  type: string;

  @ApiProperty({ description: '适合用餐时间', type: [String], enum: ['breakfast', 'lunch', 'dinner'] })
  @IsArray()
  @Transform(({ value }) => Array.isArray(value) ? value : [value])
  mealTypes: string[];

  @ApiProperty({ description: '辣度等级', minimum: 0, maximum: 5 })
  @IsNumber()
  spicyLevel: number;

  @ApiProperty({ description: '所需时间（分钟）' })
  @IsNumber()
  cookingTime: number;

  @ApiProperty({ description: '标签' })
  @IsArray()
  @IsOptional()
  tags?: string[];

  @ApiProperty({ description: '菜品图片链接' })
  @IsString()
  @IsOptional()
  imageUrl?: string;
}

export class RecipeFilterDto {
  @ApiProperty({ description: '是否接受辣食' })
  @IsOptional()
  @Transform(({ value }) => value === 'true')
  @IsBoolean()
  spicy?: boolean;

  @ApiProperty({ description: '可接受的最高辣度' })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  spicyLevel?: number;

  @ApiProperty({ description: '过敏食材' })
  @IsOptional()
  @Transform(({ value }) => (value ? value.split(',') : []))
  @IsArray()
  allergies?: string[];
}